package com.imti.mall.sale.controller;


import com.imti.mall.common.Api.CommonPage;
import com.imti.mall.common.Api.CommonResult;
import com.imti.mall.model.pms.pojo.PmsBrand;
import com.imti.mall.model.pms.vo.PmsBrandVo;
import com.imti.mall.model.sms.pojo.SmsFlashPromotion;
import com.imti.mall.sale.service.SmsFlashPromotionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * ClassName: SmsFlashPromotionController
 * Description:
 * date: 2022/9/20 0:35
 *
 * @author: youhun
 * @version:
 * @since JDK 1.8
 */
@RestController
@RequestMapping("/api/v1/sale")
@Api(tags = "限时购管理")
public class SmsFlashPromotionController {
    @Autowired
    SmsFlashPromotionService smsFlashPromotionService;

    @ApiOperation("添加限时购数据")
    @PostMapping(value = "/addSmsFlashPromotion")
    public CommonResult addSmsFlashPromotion(@RequestBody SmsFlashPromotion smsFlashPromotion) {
        boolean req = smsFlashPromotionService.addSmsFlashPromotion(smsFlashPromotion);
        if(req){
            return CommonResult.success("添加成功");
        }else {
            return CommonResult.failed("添加失败");
        }

    }

    @ApiOperation("根据ID修改限时购数据")
    @PostMapping (value = "/updateSmsFlashPromotion")
    public CommonResult updateSmsFlashPromotion(@RequestBody SmsFlashPromotion smsFlashPromotion) {
        Integer req = smsFlashPromotionService.updateSmsFlashPromotion(smsFlashPromotion);
        if(req>0){
            return CommonResult.success("修改成功");
        }else {
            return CommonResult.failed("修改失败");
        }

    }

    @ApiOperation("根据ID修改限时购数据")
    @PostMapping (value = "/updateSmsFlashPromotionToStatus")
    public CommonResult updateSmsFlashPromotionToStatus( SmsFlashPromotion smsFlashPromotion) {
        Integer req = smsFlashPromotionService.updateSmsFlashPromotion(smsFlashPromotion);
        if(req>0){
            return CommonResult.success("修改成功");
        }else {
            return CommonResult.failed("修改失败");
        }

    }


    @ApiOperation("删除限时购数据")
    @PostMapping (value = "/deleteSmsFlashPromotion/{id}")
    public CommonResult deleteSmsFlashPromotion(@PathVariable("id") Long id) {
        SmsFlashPromotion smsFlashPromotion=new SmsFlashPromotion();
        smsFlashPromotion.setId(id);
        boolean req = smsFlashPromotionService.deleteSmsFlashPromotion(smsFlashPromotion);
        if(req){
            return CommonResult.success("删除成功");
        }else {
            return CommonResult.failed("删除失败");
        }

    }

    /**
     * 查询限时购列表
     * @param smsFlashPromotion
     * @param pageSize
     * @param pageNum
     * @return
     */
    @ApiOperation(value = "查询限时购")
    @PostMapping(value = "/findSmsFlashPromotion" )
    public CommonResult findSmsFlashPromotion
    ( SmsFlashPromotion smsFlashPromotion,
     @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
     @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        List<SmsFlashPromotion> list = smsFlashPromotionService.findSmsFlashPromotion(smsFlashPromotion,pageSize, pageNum);
       // Integer total=smsFlashPromotionService.countSmsFlashPromotion(smsFlashPromotion);
        if(list.size()>0){
            return CommonResult.success(CommonPage.restPage(list));
        }else {
            return CommonResult.success("未查询到信息");
        }
    }


}
